-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Offering default methods on ParameterizedJob #2864
Offering default methods on ParameterizedJob #2864
Conversation
This pull request originates from a CloudBees employee. At CloudBees, we require that all pull requests be reviewed by other CloudBees employees before we seek to have the change accepted. If you want to learn more about our process please see this explanation. |
* Cancels a scheduled build. | ||
* @see ParameterizedJobMixIn#doCancelQueue | ||
*/ | ||
@RequirePOST |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kinda 🐛 since it advertises non-Restricted & non-RequirePOST method in all ParameterizedJob
implementations. Even though it is a historic API in AbstractProject, I am not sure we want to offer it in other job types
* Schedules a new build command. | ||
* @see ParameterizedJobMixIn#doBuild | ||
*/ | ||
default void doBuild(StaplerRequest req, StaplerResponse rsp, @QueryParameter TimeDuration delay) throws IOException, ServletException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, no Restricted/RequirePOST annotations here? I am not sure it is safe to offer such default impl. 🐛 , but probably I miss something.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original had neither annotation. @Restricted
cannot be added compatibly. @RequirePOST
is unwanted since the implementation checks the request method explicitly.
* Currently only String parameters are supported. | ||
* @see ParameterizedJobMixIn#doBuildWithParameters | ||
*/ | ||
default void doBuildWithParameters(StaplerRequest req, StaplerResponse rsp, @QueryParameter TimeDuration delay) throws IOException, ServletException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
The public doBuild
method that is being moved does not currently have any annotations, so while I think it should have a @RequirePOST
annotation, this refactoring is not making the code worse than it already is and therefore the lack of an annotation is not blocking this PR IMHO
From what I see it adds new API to the ParameterizedJob interface (new default method |
Well |
return getParameterizedJobMixIn().scheduleBuild(quietPeriod, c); | ||
} | ||
|
||
// omitting scheduleBuild2(int, Action...) since it is defined in SCMTriggerItem (could include less commonly used overloads if desired) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually as per this tip it could be defined here. Implementing classes would still need to define the method, but at least they could select a known super
implementation, which is probably more discoverable than looking for similar methods on a mixin.
|
||
// omitting scheduleBuild2(int, Action...) since it is defined in SCMTriggerItem (could include less commonly used overloads if desired) | ||
|
||
// cannot offer makeSearchIndex() since it is defined in Job |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case would still be tricky however, since the defining method is protected
and we do not really want to force implementations to override it as public
.
* Schedules a new build command. | ||
* @see ParameterizedJobMixIn#doBuild | ||
*/ | ||
default void doBuild(StaplerRequest req, StaplerResponse rsp, @QueryParameter TimeDuration delay) throws IOException, ServletException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original had neither annotation. @Restricted
cannot be added compatibly. @RequirePOST
is unwanted since the implementation checks the request method explicitly.
Test failures are bogus. Withdrawing for the moment since I want to check if I can offer |
Hmm,
seems like exactly what jenkinsci/bridge-method-injector#14 should have been solving. Investigating. |
Explained a week ago why the design is intentional; no response since.
BTW test failures in this & related PRs are due to INFRA-1176; will make sure tests pass before merging. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have checked all usages of "instanceof BuildableItem". Actually there are extra implementations in tests, but I do not see anything risky within jenkinsci org and several other repos I usually check. And yes, the ParameterizedJobMixIn seems to be always buildable according to Javadoc
Here is a list of ones which attracted my attention:
- SAFE - https://github.com/jenkinsci/github-plugin/blob/93d40692ff3866705175624e93ec584d4ac88132/src/main/java/org/jenkinsci/plugins/github/util/JobInfoHelpers.java#L47-L57 => 'item instanceof Job ' check leads to another branch
- LIKELY SAFE - https://github.com/jenkinsci/blueocean-plugin/blob/7416f58310e3a72a24d93a95e435d1db9cbc9d2d/blueocean-rest-impl/src/main/java/io/jenkins/blueocean/service/embedded/rest/QueueUtil.java#L59
- invokes doomsday error otherwise. likely the BO code should just invoke
Job#isBuildable()
- CC @i386 just in case
- invokes doomsday error otherwise. likely the BO code should just invoke
- SAFE - https://github.com/i-m-c/jenkins-inheritance-plugin (my favorite source of edge cases outside jenkinsci) - implements Project, which is already buildable
- LIKELY SAFE: Trigger plugins. From what I see, triggers will become
isApplicable()
to BuildableItem instances - SAFE - https://github.com/jenkinsci/computer-queue-plugin/blob/4c2091b021960c7ac1d73a7bd504ef1ee3208831/src/main/java/org/jenkinsci/plugins/computerqueue/ComputerQueue.java#L24 , no idea what the item could be doing there if it is not buildable
*/ | ||
public interface ParameterizedJob extends hudson.model.Queue.Task, hudson.model.Item { | ||
public interface ParameterizedJob<JobT extends Job<JobT, RunT> & ParameterizedJobMixIn.ParameterizedJob<JobT, RunT> & Queue.Task, RunT extends Run<JobT, RunT> & Queue.Executable> extends BuildableItem { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To follow-up on my bug in #2874 (comment) . Effectively it makes any any Parameterized job explicitly buildable. After some consideration, it seems to be a valid change according to the ParameterizedJobMixIn documentation.
🐜 since I expect ParameterizedJob Javadoc to explicitly say it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well the mixin Javadoc does say
be scheduled in various ways
which I guess is enough. Anyway BuildableItem
is an interface which is not used all that much and not especially interesting to people grokking this code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🐝 after the review of possible regressions due to making all ParameterizedJob
s BuildableItem
s.
@reviewbybees done, passing to @jenkinsci/code-reviewers
@@ -143,7 +143,7 @@ | |||
* @see AbstractBuild | |||
*/ | |||
@SuppressWarnings("rawtypes") | |||
public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends AbstractBuild<P,R>> extends Job<P,R> implements BuildableItem, LazyBuildMixIn.LazyLoadingJob<P,R>, ParameterizedJobMixIn.ParameterizedJob { | |||
public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends AbstractBuild<P,R>> extends Job<P,R> implements BuildableItem, LazyBuildMixIn.LazyLoadingJob<P,R>, ParameterizedJobMixIn.ParameterizedJob<P, R> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implements BuildableItem
is now redundant, could be removed I guess.
I have checked all usages of "instanceof BuildableItem".
The only implementations of ParameterizedJob
were already BuildableItem
s so retrofitting it to implement that interface should not cause any behavioral change even if someone were doing that instanceof
check.
According to the discussion at the governance meeting on May 10, merging it towards 2.61 |
* Offering default methods on ParameterizedJob. * Javadoc typo. * Cleaner use of default methods in ParameterizedJob. * Need to pick up jenkinsci/bridge-method-injector#15 to be able to build. * Using new type bounds. * bridge-method-injector 1.17
Description
Allows subtypes to have less boilerplate. Mentioned as a design pattern in #2730.
Changelog entries
None required.
Desired reviewers
@reviewbybees